﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeuzenAdministratie
{
    public partial class MemberAdmin : Form
    {
        DBConnect db = new DBConnect();

        public MemberAdmin()
        {
            InitializeComponent();
            getData();
        }

        public void getData()
        {
            dataGridView1.DataSource = db.Select();
            this.dataGridView1.Columns["member_id"].Visible = false;//we hoeven member_id niet weer te geven
            this.dataGridView1.Columns["deleted"].Visible = false;
        }


        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            using (MemberProperties mp = new MemberProperties(this.dataGridView1.CurrentRow.Cells[0].Value.ToString()))//member_id doorgeven aan memberproperties
            {
                mp.ShowDialog();
            }
            getData();//refresh datagridview
        }

        private void AddMember_Click(object sender, EventArgs e)
        {
            using (MemberProperties mp = new MemberProperties())
            {
                mp.ShowDialog();
            }
            getData();//refresh datagridview
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (MemberProperties mp = new MemberProperties(this.dataGridView1.CurrentRow.Cells[0].Value.ToString()))//member_id doorgeven aan memberproperties
            {
                mp.ShowDialog();

            }
            getData();//refresh datagridview

        }

        private void btnVerwijder_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Weet je zeker dat je dit lid wil verwijderen?",
                "Verwijderen bevestigen", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string member_id = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                DBConnect db = new DBConnect();
                db.Delete(member_id);
                getData();
            }


        }

        private void btnSeePresence_Click(object sender, EventArgs e)
        {
            MemberPresence prop = new MemberPresence(this.dataGridView1.CurrentRow.Cells[4].Value.ToString());//zou KNSA moeten returnen
            prop.Show();
        }

        private void btnAanwezigDag_Click(object sender, EventArgs e)
        {
            PresenceDay pres = new PresenceDay();
            pres.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            DBConnect db = new DBConnect();
            db.Backup();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DBConnect db = new DBConnect();
            db.Restore();
        }

    }
}
